<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="/statics/js/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: "get",
                url: "/grade/queryAll",
                success: function (result) {
                    $("select[name='grade.id']").append("<option value='-1'>--请选择--</option>");
                    $.each(result, function (index, g) {
                        $("select[name='grade.id']").append("<option value='" + g.id + "'>" + g.gradeName + "</option>");
                    });
                }
            });
        })

        function ajaxadd() {
            $.ajax({
                type: "post",
                data: $("#add").serialize(),
                //dataType:"json",
                url: "/student/save",
                success: function (result) {
                    if (result !== "yes") {
                        alert("添加失败");
                    } else {
                        alert("添加成功");
                        location.href = "/student/queryByName"
                    }
                }

            })
        }
    </script>
</head>
<body>
<div align="center">
    <h2>添加学生信息</h2>
    <form id="add" method="post">
        <table border="1" cellspacing="0" width="50%">
            <tr>
                <td>学生姓名：</td>
                <td>
                    <input type="text" name="studentName">
                </td>
            </tr>
            <tr>
                <td>性别：</td>
                <td>
                    <select name="gender">
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>年龄：</td>
                <td><input type="number" name="age"></td>
            </tr>
            <tr>
                <td>学号：</td>
                <td><input type="text" name="studentNum"></td>
            </tr>
            <tr>
                <td>所在班级：</td>
                <td>
                    <select name="grade.id">

                    </select>
                </td>
            </tr>
            <tr>
                <td><input type="button" onclick="ajaxadd()" value="保存"></td>
                <td><input type="reset" value="重置"></td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>
